package com.hp.service.observer;

import com.hp.service.observer.observer.ConcreteObserver;
import com.hp.service.observer.observer.Observer;
import com.hp.service.observer.subject.ConcreteSubject;
import com.hp.service.observer.subject.Subject;

// 客户端代码
public class ObserverPatternDemo {
    public static void main(String[] args) {
        Subject subject = new ConcreteSubject();
 
        Observer observer1 = new ConcreteObserver("Observer 1");
        Observer observer2 = new ConcreteObserver("Observer 2");
 
        subject.addObserver(observer1);
        subject.addObserver(observer2);
 
        subject.notifyObservers("Hello Observers!");

        subject.removeObserver(observer1);
        subject.notifyObservers("==================Hello Observers!");
    }
}